extends AcceptDialog

@onready var line_edit = $VBoxContainer/LineEdit
@onready var random_button = $VBoxContainer/HBoxContainer/RandomButton
@onready var confirm_button = $VBoxContainer/HBoxContainer/ConfirmButton

var on_seed_selected: Callable

func _ready():
	random_button.pressed.connect(_on_random_pressed)
	confirm_button.pressed.connect(_on_confirm_pressed)
	
	# 设置默认值
	line_edit.text = "0"

func _on_random_pressed():
	var random_seed = randi()
	line_edit.text = str(random_seed)

func _on_confirm_pressed():
	var seed_text = line_edit.text
	var seed_value = 0
	
	if seed_text.is_valid_int():
		seed_value = seed_text.to_int()
	else:
		# 如果不是有效数字，使用随机种子
		seed_value = randi()
	
	# 调用回调函数
	if on_seed_selected.is_valid():
		on_seed_selected.call(seed_value)
	
	hide()

func show_dialog(callback: Callable):
	on_seed_selected = callback
	popup_centered()
